﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Management;

namespace regExport
{
    class Copying_Replacing
    {


        static public void Copy(string path, string path2 )
        {
           try 
        {           
            // Ensure that the target does not exist.
            File.Delete(path2);

            // Copy the file.
            File.Copy(path, path2);
            Console.WriteLine("{0} copied to {1}", path, path2);
        } 

        catch (Exception e) 
        {
            //This catches if the user has been copied to this server. 
            Console.WriteLine("Double copying is not allowed, as expected.");
            Console.WriteLine(e.ToString());
        }
    }
     
        static public void Replacement(string filepath, string oldvalue, string newvalue)
        {
            //Reads the file into a string and then makes necessary changes to that specific file. 

            string text = File.ReadAllText(filepath);
            text = text.Replace(oldvalue, newvalue);
            File.WriteAllText(filepath, text);
        }
    }
}
